package org.example.main;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.example.pojo.User;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) throws IOException {

        System.out.println("Hello world!");
//        加载核心配置文件，获取 SqlSessionFactory 对象


        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        System.out.println(sqlSessionFactory);
        //     获取 SqlSession 对象，执行 SQL 语句

        SqlSession session = sqlSessionFactory.openSession();
        User user = session.selectOne("test.selectById", 1);

        System.out.println(user);


//                释放资源
        session.close();

    }
}